import {ServicePrefixEnum} from "@/enums/commonEnum";
import {RequestEnum} from "@/enums/httpEnum";
import {defHttp} from "@/utils/http/axios";
import type { AxiosRequestConfig } from 'axios';
export interface MailTemplateVO {
  id: number
  name: string
  code: string
  accountId: number
  nickname: string
  title: string
  content: string
  params: string
  status: number
  remark: string
}

export interface MailSendReqVO {
  mail: string
  templateCode: string
  templateParams: Map<String, Object>
}


const  MODULAR = '/system/mail-template'
export const Api = {

  GetMailTemplatePage: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/page`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetMailTemplate: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/get`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  CreateMailTemplate: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/create`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  updateMailTemplate: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  DeleteDictData: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/delete`,
    method: RequestEnum.DELETE,
  } as AxiosRequestConfig,
  SendMail: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/send-mail`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
}


// 查询邮件模版列表
export const getMailTemplatePage = (params: PageParam) => {
  return defHttp.request({ ...Api.GetMailTemplatePage,params: params })
}

// 查询邮件模版详情
export const getMailTemplate =  (id: number) => {
  let params = { id: id }
  return defHttp.request({ ...Api.GetMailTemplate,params: params })
}

// 新增邮件模版
export const createMailTemplate = (data: MailTemplateVO) => {
  let params = { data: data }
  return defHttp.request({ ...Api.CreateMailTemplate,params:params })
}

// 修改邮件模版
export const updateMailTemplate = (data: MailTemplateVO) => {
  let params = { data: data }
  return defHttp.request({ ...Api.updateMailTemplate,params:params })
}

// 删除邮件模版
export const deleteMailTemplate = (id: number) => {
  let params = { id: id }
  return defHttp.request({ ...Api.DeleteDictData,params: params })
}

// 发送邮件
export const sendMail = (data: MailSendReqVO) => {
  let params = { data: data }
  return defHttp.request({ ...Api.SendMail,params:params })

}
